<template>
	<view class="content">
		<LotteryDraw :grid_info='grid_info' :lottery_draw_param='lottery_draw_param' @get_winingIndex='get_winingIndex'  @luck_draw_finish='luck_draw_finish'></LotteryDraw>
	</view>
</template>

<script>
import LotteryDraw from '../../../components/SJ-LotteryDraw/SJ-LotteryDraw.vue';
export default {
	components:{
		LotteryDraw
	},
	data() {
		return {
			grid_info : [{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "手机"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "零食包"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "口红"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "谢谢参与"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "压缩饼干"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "水杯"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "QQ糖"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "耳机"
				},
				{
					logo: "../../../static/SJ-LotteryDraw/SJ-LotteryDraw.png",
					text: "谢谢参与"
				},
			],
			lottery_draw_param:{
				startIndex: 0, //开始抽奖位置，从0开始
				totalCount: 4, //一共要转的圈数
				winingIndex: 4, //中奖的位置，从0开始
				speed: 50 //抽奖动画的速度 [数字越大越慢,默认100]
			},
			cid:'',
			cjmsg:'',
		};
	},
	onLoad() {
		uni.getStorage({
			key: 'openid',
			success: (res) => {
				this.openid = res.data
				this.setAjax()
			},
			fail: () => {
				uni.navigateTo({
					url: '../../login/login'
				});
			}
		});
	},
	methods: {
		setAjax(){
			uni.request({
				url: 'https://app.t9y9y9.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.redpaper.chou&app=1',
				method: 'POST',
				data: {'openid':this.openid},
				header:{'Content-Type':'application/x-www-form-urlencoded'},
				success: res => {
					console.log(res)
					this.cid = res.data.cid
					if(res.data.error==1){
						uni.showModal({
						    title: '提示',
						    content: res.data.message,
						    success: function (res) {
						        if (res.confirm) {
						            uni.switchTab({
						                url: '../../member/member'
						            });
						        } else if (res.cancel) {
						            uni.switchTab({
						                url: '../../member/member'
						            });
						        }
						    }
						})	
					}
				},
				fail: () => {},
				complete: () => {}
			});
		},
		// 修改获奖位置（可以在这里获取后台的数据
		get_winingIndex(callback){
			uni.request({
				url: 'https://app.t9y9y9.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.redpaper.choujiang&app=1',
				method: 'POST',
				data: {
					'openid':this.openid,
					'cid':this.cid,
					},
				header:{'Content-Type':'application/x-www-form-urlencoded'},
				success: res => {
					console.log(res)
					this.lottery_draw_param.winingIndex=res.data.int;
					this.cjmsg=res.data.message;
					callback(this.lottery_draw_param);
				},
				fail: () => {},
				complete: () => {}
			});
			
		},
		// 抽奖完成
		luck_draw_finish(param){
			uni.showToast({
			    title: this.cjmsg,
			    duration: 2000
			});
			setTimeout(()=>{
			
				 uni.switchTab({
						 url: '../../member/member'
				 });
			
			},5000)
			
			// console.log(param)
			// console.log(`抽到第${param+1}个方格的奖品`)
		}
		
	}
};
</script>

<style scoped>
.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

</style>
